﻿using Devil;

namespace GameToolkit
{
    [System.Serializable]
    public struct NameID : System.IEquatable<NameID>
    {
        public static int GetID(string name)
        {
            return name.IgnoreCaseToHash();
        }

        public string name;
        public int id;


        public NameID(int id, string name)
        {
            this.id = id;
            this.name = name;
        }

        public NameID(string name)
        {
            this.id = name.IgnoreCaseToHash();
            this.name = name;
        }

        public bool Equals(NameID other)
        {
            return this.id == other.id;
        }

        public override int GetHashCode()
        {
            return id;
        }

        public override string ToString()
        {
            return name;
        }

        public override bool Equals(object obj)
        {
            if (obj is NameID)
                return id == ((NameID)obj).id;
            else
                return false;
        }

        public static bool operator ==(NameID a, NameID b)
        {
            return a.id == b.id;
        }

        public static bool operator !=(NameID a, NameID b)
        {
            return a.id != b.id;
        }

        public static implicit operator NameID(string txt)
        {
            return new NameID(txt);
        }
    }

}